package com.supermarket.shop.system.domain;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Commodity {
    private Integer id;
    private String name;
    private Integer price;
    private Integer stock;
    private Date date;
    private String pop;

    public Commodity(Integer id, String name, Integer price, Integer stock, Date date, String pop) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.date = date;
        this.pop = pop;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getPop() {
        return pop;
    }

    public void setPop(String pop) {
        this.pop = pop;
    }

    public Commodity() {
    }
    //展示商品类的相关信息
    public void show(){
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
        String timePattern = sdf.format(this.date);
        System.out.println(this.id+"\t\t\t"+this.name+"\t\t\t"+this.price+"\t\t\t"+this.stock+"\t\t\t"+timePattern+"\t\t\t"+this.pop);
    }
    //读取字符串数组中的元素将其转化为commodity商品对象
    public  static Commodity getCommodity(String[] split){
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
        Date date= null;
        try {
            date = sdf.parse(split[4]);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Commodity commodity=new Commodity(Integer.valueOf(split[0]),
                split[1],Integer.valueOf(split[2]),Integer.valueOf(split[3]),date,split[5]);
        return commodity;
    }
}
